1. Field of the Invention
This invention relates to graphic systems. More particularly, this invention relates to fast, efficient stencil buffer clearing.
2. Description of the Related Art
Graphics processing is an important feature of modern high-performance computing systems. In graphic processing, mathematical procedures are implemented to render, or draw, graphic primitives, e.g., triangles or rectangles, on a display to produce desired visual images. Real time graphics processing is based on the high-speed processing of graphic primitives to produce visually pleasing moving images.
Early graphic systems were limited to displaying image objects comprised of graphic primitives without proper shadowing. Adding the casting of shadows provides more realism than present in early images. To enhance image quality, shadow generation techniques such as stenciled shadow volumes were introduced to add realistic shadows to rendered images. The stenciled shadow volume technique depends on the use of a stencil buffer, described in more detail subsequently. Similarly, other rendering techniques such as for Constructive Solid Geometry depend on the stencil buffer.
Graphics are typically designed by graphics designers who use application program interfaces (APIs), which are standardized software interfaces, to render desired images that can be run on multiple platforms, operating systems, and hardware. Examples of APIs include the Open Graphics Library (OpenGL®) and D3D™. This enables graphic designers to design graphics without knowing any of the specifics regarding the system hardware or how their commands will be implemented. Application program interfaces (APIs) are widely accepted, powerful, and are good vehicles for implementing features such as those of the present invention.
When a graphics image is rendered each pixel of that image is given a set of values that are stored in buffer memory and that are used to “display” the pixel. For example, each pixel can have a color value that is stored in a color buffer and a depth value that is stored in a depth (Z) buffer memory.
In addition to color and depth buffer memories, each pixel can also have an entry in a stencil buffer. A stencil buffer is a memory comprised of stencil registers that can control the update of a pixel. Typical uses of stencil buffers include defining regions for masking pixel updates, constructive solid geometry, and adding shadows. For example, if portions of a “background” are to show through windows, the stencil registers for the background that will show can be given values while the stencil registers for other areas can be cleared. The value of the stencil registers can then be compared to a threshold value and used to mask-out areas that are not to show through (or mask-in the areas that are).
As previously noted a stencil buffer can also be used to add shadows. Shadows can enhance an image by producing a more natural-looking image. Since graphic shadows correspond to real world shadows, graphic shadows represent the effects of shading caused by surfaces that block light. Since a given image may have both multiple light sources and multiple light-blocking surfaces the shadow value of each pixel depends on the shading produced by all of the light sources and all of the light-blocking surfaces. Images with convincing shadows can be produced using one or more shadow algorithms that store values in a stencil buffer. Most shadow algorithms “turn off” the light sources, determine a base shadow value for each pixel, then selectively turn on the individual light sources, determine the shadow value produced by each light source, and then blend the result to produce a composite shadow value for each pixel.
The foregoing overview has been presented in a simplified manner for clarity. Implementing the foregoing is often performed using graphics design packages. Such packages enable a graphics designer to specify numerous editing and formatting attributes, including shadow algorithms and other uses of the stencil buffer.
When using a stencil buffer, such as when implementing a shadow algorithm, it is typically necessary to first clear the stencil registers. For example, when determining the effects of light sources on the stencil value of each pixel it is typically necessary to clear the stencil buffer multiple times, e.g., once for each light source. By clearing it is meant setting the value of cleared stencil registers to some predetermined value, often, but not always, 00hex. While clearing a stencil register is not particularly difficult, say by writing a predetermined value to each stencil register, writing that value to each stencil register is a fairly slow process given that millions of stencil registers might exist. Having to do so multiple times, such as when shadow rendering, can become excessively time consuming.
Additionally, stencil-only frame buffer clears are increasingly common as 3D applications are now using rendering algorithms such as stenciled shadow volume rendering for multiple light sources in a single frame, recent “soft” stenciled shadow volume techniques, and stencil-based constructive solid geometry techniques. In such algorithms there are multiple stencil buffer clears for each depth buffer clear. Additionally in many cases, these algorithms often do not require all 8 stencil bitplanes for their stencil requirements. In such cases, there is the potential for using some of the stencil register bitplanes for other purposes.
In view of the foregoing, a method of effectively clearing stencil registers at high speed would be beneficial. Also beneficial would be methods of enabling a graphics designer to control the clearing of stencil registers such that the use of the stencil buffer is not negatively impacted. Also beneficial would be a high speed system and method for effectively clearing stencil registers such that numerical algorithms that use the stencil buffer are not negatively impacted.